import Vue from 'vue'
import App from './App'
import api from './common/api'
import store from './store'

let $host = 'https://shop.zdsy.shop' // 接口地址
Vue.prototype.$host = $host

let $uniHost = 'https://shop.zdsy.shop' // uni端访问地址，用于分享H5地址
Vue.prototype.$uniHost = $uniHost

// 设备判断
let $deviceType = 'web'
//#ifdef MP
$deviceType = 'wxapp'
//#endif
//#ifdef APP-PLUS
$deviceType = 'mobile'
//#endif
Vue.prototype.$deviceType = $deviceType

// 请求接口
let $api = new api({
  host: $host,
  device_type: $deviceType
})
Vue.prototype.$api = $api

// 加载蒙层
Vue.prototype.$loading = () => {
  uni.showLoading({
    mask: true
  })
  setTimeout(() => {
    uni.hideLoading();
  }, 2000);
}

// toast
Vue.prototype.$toast = (title = '') => {
  uni.showToast({
    title: title,
    icon: 'none'
  })
}

// 拨打客服电话
Vue.prototype.$makePhoneCall = (phone = '114') => {
  uni.makePhoneCall({
    phoneNumber: phone
  });
}

// 登录判断，传入ture则提示登录，默认不提示
Vue.prototype.$isLogin = (showModal = false) => {
  console.log(showModal)
  console.log(store.state.token)
  if (store.state.token) {
    return true
  } else {
    if (showModal) {
      uni.showModal({
        title: '提示',
        content: '请先登录账号',
        confirmText: '去登录',
        success: res => {
          if (res.confirm) {
            uni.navigateTo({
              url: '/pages/login/login'
            })
          }
        }
      });
    }
    return false
  }
}

// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView)

Vue.config.productionTip = true

App.mpType = 'app'

const app = new Vue({
  store,
  ...App
})

app.$mount()
